// pages/index/BillingParticulars.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    billUnit:{
      id:0,
      title:"",
      time:"",
      detail:""
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var appThis = this;
    var getResult = false;
    var billUnit = this.data.billUnit;
    wx.getStorage({
      key: options.billUnitId,
      success: function(res) {
        getResult = true;
        billUnit.id = new Number(res.data.id);
        billUnit.time = res.data.date + " " + res.data.time;
        billUnit.detail = res.data.areaType + "," + res.data.textArea;
        switch (res.data.bType) {
          case 0: {//支出
            billUnit.title = "支出:" + res.data.money + "元";
            break;
          }
          case 1: {//收入
            billUnit.title = "收入:" + res.data.money + "元";
            break;
          }
          default: console.error("发生异常"); break;
        }
        appThis.setData({
          billUnit: billUnit,
        })
      },
      fail: function(res) {
        getResult = false;
        wx.showToast({
          title: "获取账单异常",
          icon:'loading'
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  deleteBilleById: function() {
    var appThis = this;
    var keyValue = new String(this.data.billUnit.id);
    console.warn(keyValue);
    wx.showModal({
      title: '是否删除',
      content: '点击确认将删除本条账单',
      success: res => {
        if (res.confirm) {
          wx.removeStorage({
            key: keyValue,
            success: function (res) {
              wx.showToast({
                title: '成功删除',
                icon: 'success'
              })
              wx.navigateBack({
                delta: 1,
              })
            },
            fail: function (res) {
              wx.showToast({
                title: '删除失败',
                icon: 'loading'
              })
            }
          })
        }
      }
    })
  }
})